﻿using System;
using System.Web.UI.WebControls;
using FFIV.Lib.Utilities;

public partial class Views_Users_AdminList : System.Web.UI.UserControl
{
	protected void Page_Load(object sender, EventArgs e)
	{
		if (!IsPostBack)
		{
			BuildAdminList();
		}
	}

	public void BuildAdminList()
	{
		Permissions currentPermission = UsersUtility.GetCurrentUserRole();

		TreeNode articleRoot = new TreeNode("文章模块");
		articleRoot.ChildNodes.Add(CreateNode("添加文章", UrlUtility.Admin_AddArticle));
		articleRoot.ChildNodes.Add(CreateNode("文章管理", UrlUtility.Admin_ManageArticles));

		articleRoot.SelectAction = TreeNodeSelectAction.Expand;


		TreeNode userRoot = new TreeNode("用户模块");

		if (currentPermission == Permissions.Admin)
		{
			articleRoot.ChildNodes.Add(CreateNode("类别管理", UrlUtility.Admin_ManageCategories));

			userRoot.ChildNodes.Add(CreateNode("添加用户", UrlUtility.Admin_RegisterUser));
			userRoot.ChildNodes.Add(CreateNode("用户管理", UrlUtility.Admin_ManageUser));
		}
		userRoot.ChildNodes.Add(CreateNode("修改信息", UrlUtility.Admin_EditUserInfo));

		userRoot.SelectAction = TreeNodeSelectAction.Expand;

		tv_AdminList.Nodes.Add(articleRoot);
		tv_AdminList.Nodes.Add(userRoot);

		tv_AdminList.ExpandAll();
	}

	private TreeNode CreateNode(string title, string href)
	{
		TreeNode node = new TreeNode();
		node.Text = title;
		node.NavigateUrl = href;
		return node;
	}
}
